using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using MobileClient.UIProcessService;

namespace MobileClient
{
	/// <summary>
	/// Summary description for ctlMultiSelectOtherEntry.
	/// </summary>
	public class ctlMultiSelectOtherEntry : Control
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.TabControl tabControl;
		private System.Windows.Forms.TabPage tabSelections;
		private System.Windows.Forms.ListView lstSelections;
		private System.Windows.Forms.TabPage tabOther;
		private System.Windows.Forms.Label lblOther;
		private System.Windows.Forms.TextBox txtOther;
		private System.Windows.Forms.ColumnHeader chdrSelection;

		private MultiSelectOtherEntry m_objEntry;

		public ctlMultiSelectOtherEntry()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			m_objEntry = null;
		}

		public MultiSelectOtherEntry Entry
		{
			get { return m_objEntry; }
			set { m_objEntry = value; }
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tabControl = new System.Windows.Forms.TabControl();
			this.tabSelections = new System.Windows.Forms.TabPage();
			this.lstSelections = new System.Windows.Forms.ListView();
			this.tabOther = new System.Windows.Forms.TabPage();
			this.lblOther = new System.Windows.Forms.Label();
			this.txtOther = new System.Windows.Forms.TextBox();
			this.chdrSelection = new System.Windows.Forms.ColumnHeader();
			// 
			// tabControl
			// 
			this.tabControl.Controls.Add(this.tabSelections);
			this.tabControl.Controls.Add(this.tabOther);
			this.tabControl.Location = new System.Drawing.Point(3, 6);
			this.tabControl.SelectedIndex = 0;
			this.tabControl.Size = new System.Drawing.Size(230, 140);
			// 
			// tabSelections
			// 
			this.tabSelections.Controls.Add(this.lstSelections);
			this.tabSelections.Location = new System.Drawing.Point(4, 22);
			this.tabSelections.Size = new System.Drawing.Size(222, 114);
			this.tabSelections.Text = "Selections";
			// 
			// lstSelections
			// 
			this.lstSelections.CheckBoxes = true;
			this.lstSelections.Columns.Add(this.chdrSelection);
			this.lstSelections.FullRowSelect = true;
			this.lstSelections.Location = new System.Drawing.Point(0, 0);
			this.lstSelections.Size = new System.Drawing.Size(220, 116);
			this.lstSelections.View = System.Windows.Forms.View.Details;
			// 
			// tabOther
			// 
			this.tabOther.Controls.Add(this.lblOther);
			this.tabOther.Controls.Add(this.txtOther);
			this.tabOther.Location = new System.Drawing.Point(4, 22);
			this.tabOther.Size = new System.Drawing.Size(222, 114);
			this.tabOther.Text = "Other";
			this.tabOther.Visible = false;
			// 
			// lblOther
			// 
			this.lblOther.Location = new System.Drawing.Point(5, 33);
			this.lblOther.Size = new System.Drawing.Size(44, 20);
			this.lblOther.Text = "Other:";
			// 
			// txtOther
			// 
			this.txtOther.Location = new System.Drawing.Point(5, 61);
			this.txtOther.Size = new System.Drawing.Size(212, 20);
			this.txtOther.Text = "";
			// 
			// chdrSelection
			// 
			this.chdrSelection.Text = "Items";
			this.chdrSelection.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.chdrSelection.Width = 210;
			// 
			// ctlMultiSelectOtherEntry
			// 
			this.Controls.Add(this.tabControl);
			this.Size = new System.Drawing.Size(236, 152);

		}
		#endregion

		public void LoadSettings()
		{
			if(m_objEntry != null)
			{
				ListViewItem lvItem;

				lstSelections.Items.Clear();

				if(m_objEntry.Options != null)
				{
					foreach(String strItem in m_objEntry.Options)
					{
						lvItem = new ListViewItem(strItem);
						lstSelections.Items.Add(lvItem);
					}
				}

                if (!String.IsNullOrEmpty(m_objEntry.OtherValue))
                {
                    txtOther.Text = m_objEntry.OtherValue;
                }
                else
                {
                    txtOther.Text = "";
                }
			}
		}

		public void SaveSettings()
		{
			if(m_objEntry != null)
			{
                if (!String.IsNullOrEmpty(txtOther.Text))
                {
                    string arrSelected = "";
                    foreach (ListViewItem lvItem in lstSelections.Items)
                    {
                        if (lvItem.Checked)
                        {
                            arrSelected += lvItem.Text + ",";
                        }
                    }

                    m_objEntry.Selections = arrSelected.Split(',');
                    m_objEntry.OtherSelected = false;
                }
                else
                {
                    m_objEntry.OtherSelected = true;
                    m_objEntry.OtherValue = txtOther.Text;
                }
			}
		}
	}
}
